package basis;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author dongyang
 * @since 2020-12-28 15:13
 */
@WebServlet(urlPatterns = "/hello")
public class HelloService extends HttpServlet {

    @Override
    public void init() throws ServletException {
        System.out.println("init without parameter");
        super.init();
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("init with parameter");
        super.init(config);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String inputString = req.getParameter("name").toUpperCase();
//        StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
//        for (StackTraceElement stackTraceElement : stackTrace) {
//            System.out.println(stackTraceElement);
//        }

        PrintWriter out = resp.getWriter();
        out.println("hello," + inputString);
    }
}
